from time import sleep

from airtest.core.api import keyevent, stop_app, swipe

from V1.air import air_directory, air_report
from V1.air.air_core import AirClick
from V1.air.air_init import air_init
from V1.page.Link1 import Link2, Link1


# 定义快手下单类
class KuaiShou:

    # 判断来源
    def determineSource(self):
        # 实例化poco
        dir = air_directory.dir
        KuaiShou_init = air_init()
        poco = KuaiShou_init.init(dir)
        # 实例化点击方法
        source_click = AirClick()
        # 返回桌面
        keyevent('HOME')
        sleep(1)
        # 打开快手
        source_click.airClickByText(poco, '快手')
        sleep(1)
        # 判断链接1还是链接2
        if source_click.airImageExists('tpl1739933643229.png'):
            KSLink1_run = Link1()
            KSLink1_run.PlaceOrder(poco)
        else:
            KSLink2_run = Link2()
            KSLink2_run.PlaceOrder(poco)
        source_click.airClickByText(poco, 'K选购链接1')


# 定义小红书取关类
class XiaoHongShu:
    def unfollow(self):
        # 实例化poco
        dir = air_directory.dir
        XiaoHongShu_init = air_init()
        poco = XiaoHongShu_init.init(dir)
        # 实例化点击方法
        source_click = AirClick()
        # 取消关注
        for i in range(5):
            for j in range(7):
                if source_click.airImageExists('tpl1747013726956.png'):
                    source_click.airClickByText(poco, '已关注')
                    source_click.airClickZuoBiao([740,1338])
                    sleep(1)
                else:
                    break
            source_click.airSwipScreen([542,2239],[580,817])

if __name__ == "__main__":
    # K = KuaiShou()
    # K.determineSource()
    X = XiaoHongShu()
    X.unfollow()